<template>
  <el-dialog
    :title="title"
    :visible="isshowdialog"
    center
    @close="EscEdit"
  >
    <el-form :model="Pagedetails">
      <el-form-item label="标题">
        <el-input v-model="Pagedetails.title" autocomplete="off" />
      </el-form-item>
      <el-form-item label="内容">
        <vue-editor v-model="Pagedetails.content" />
      </el-form-item>
    </el-form>
    <el-row slot="footer">
      <el-button type="primary" size="small" @click="EditSuccess">确 定</el-button>
      <el-button size="small" @click="EscEdit">取 消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { EditPage, AddPage } from '@/api/page'
import { VueEditor } from 'vue2-editor'
export default {
  components: {
    VueEditor
  },
  props: {
    // eslint-disable-next-line vue/prop-name-casing
    Pagedetails: {
      type: Object,
      required: true
    },
    isshowdialog: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '新增页面'
    }
  },
  methods: {
    EscEdit() {
      this.$emit('update:isshowdialog', false)
    },
    async EditSuccess() {
      if (this.Pagedetails.id) {
        console.log('编辑页面', this.Pagedetails)
        await EditPage(this.Pagedetails)
        this.$message.success('保存成功')
      } else {
        console.log('添加页面', this.Pagedetails)
        await AddPage(this.Pagedetails)
        this.$message.success('添加成功')
      }
      this.$emit('UpdateList')
      this.$emit('update:isshowdialog', false)
    }
  }
}
</script>

<style>

</style>
